package gamecode;

public class Vector2D {

	private double magnitude;
	private double direction; // Note: Angle direction is in degrees
	
	public static double wrapDirection(double d) {
		while(d >= 360) d -= 360;
		while(d < 0) d += 360;
		return d;
	}
	
	public Vector2D() {
		magnitude = 0;
		direction = 0;
	}
	
	public Vector2D(double m, double d) {
		magnitude = m;
		direction = wrapDirection(d);
	}
	
	public Vector2D(Vector2D vec) {
		this.setDirection(vec.getDirection());
		this.setMagnitude(vec.getMagnitude());
	}
	
	public void setVector(Vector2D vec) {
		this.setDirection(vec.getDirection());
		this.setMagnitude(vec.getMagnitude());
	}
	
	public void setVector(double d, double m) {
		this.setDirection(d);
		this.setMagnitude(m);
	}
	
	public void setDirection(double d) {
		direction = wrapDirection(d);
	}
	
	public void addDirection(double d) {
		direction = wrapDirection(direction + d);
	}
	
	public void setMagnitude(double m) {
		magnitude = m;
	}
	
	public void addMagnitude(double m) {
		magnitude += m;
	}
	
	public double getDirection() {
		return direction;
	}
	
	public double getMagnitude() {
		return magnitude;
	}
	
	public DPoint getXY(int delta) {
		double X = Math.cos(Math.toRadians(direction)) * magnitude * delta;
		double Y = Math.sin(Math.toRadians(direction)) * magnitude * delta;
		return new DPoint(X, Y);
	}
	
	public static DPoint getXY(double d, double m, int delta) {
		double X = Math.cos(Math.toRadians(d)) * m * delta;
		double Y = Math.sin(Math.toRadians(d)) * m * delta;
		return new DPoint(X, Y);
	}
}